package me.rvj.servlet;

import me.rvj.dao.UserDao;
import me.rvj.entity.User;
import net.sf.json.JSONObject;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @program: JavaWeb
 * @description: 获取用户信息
 * @author: Rv_Jiang
 * @date: 2021/7/7 22:13
 */
@WebServlet(name = "GetUserInfoServlet",value = "/GetUserInfoServlet")
public class GetUserInfoServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("application/json;charset=utf-8");
        String userName = req.getParameter("userName");
        List<User> userList = UserDao.getUserList();
        for (User item : userList) {
            if(item.getUserName().equals(userName)){
                JSONObject user_Json = new JSONObject();
                user_Json.put("userName",item.getUserName());
                user_Json.put("uuid",item.getUuid());
                resp.getWriter().print(user_Json);
                return;
            }

        }
    }
}
